import csv
import numpy as np
from collections import Counter

# Function to calculate the mode
def read_class_data(csv_name):
    """
    Read a CSV file and return a list of data.
    :param csv_name: The name of the CSV file.
    :return: A list containing the data from the CSV file.
    """
    with open(csv_name, 'r') as file:
        reader = csv.reader(file)
        next(reader)  # Skip the header row
        return list(reader)

# Read data from three different class CSV files
class1_data = read_class_data('class1.csv')
class2_data = read_class_data('class2.csv')
class3_data = read_class_data('class3.csv')

# Initialize an empty list to store math scores
math_scores = []

# Add math scores from class1 data to the list
for row in class1_data:
    math_scores.append(int(row[2]))

# Add math scores from class2 data to the list
for row in class2_data:
    math_scores.append(int(row[2]))

# Add math scores from class3 data to the list
for row in class3_data:
    math_scores.append(int(row[2]))

# Convert the list of math scores to a NumPy array
math_scores_array = np.array(math_scores)

# Calculate the mean score
mean_score = np.mean(math_scores_array)
# Calculate the median score
median_score = np.median(math_scores_array)
# Calculate the standard deviation
std_deviation = np.std(math_scores_array)
# Calculate the variance
variance = np.var(math_scores_array)

def calculate_mode(data):
    """
    Calculate the mode of the data.
    :param data: A list or array containing the data.
    :return: The mode of the data.
    """
    counter = Counter(data)
    mode = counter.most_common(1)[0][0]
    return mode

# Calculate the mode score
mode_score = calculate_mode(math_scores_array)

# Print the calculated statistical measures
print(f"Mean: {mean_score:.2f}")
print(f"Median: {median_score:.2f}")
print(f"Mode: {mode_score:.2f}")
print(f"Standard Deviation: {std_deviation:.2f}")
print(f"Variance: {variance:.2f}")